<template>
  <view>
  <!-- 搜索区域 -->
  <my-search :bgcolor="'#c00000'" :radius="15" @clickSearch="clickSearchHandler"></my-search>
  
  <!-- 滚动条区域 -->
  <view class="scroll-view-container">
    <scroll-view class="left-scroll-view" :style="{height: screenHeight+'px'}" scroll-y="true">
      <block  v-for="(item,index) in cateList" :key="item.cat_id">
        <view :class="['left-scroll-item',index===activeIndex?'active':'']" @click="activeChange(index)">{{item.cat_name}}</view>
      </block>
    </scroll-view>
    
    <scroll-view class="right-scroll-view" scroll-y="true" :style="{height:screenHeight+'px'}" :scroll-top="scrollTop">
      <view class="cate-level2" v-for="(item2,index2) in cateLevel2" :key="index2">
           <view class="cate-level2-title">/ {{item2.cat_name}} /</view>
           
           <view class="cate-level3-list">
             <view class="cate-level3-list-item" v-for="(item3,index3) in item2.children" :key="index3" @click="gotoGoodsList(item3)">
                <image :src="item3.cat_icon"></image>
                <text>{{item3.cat_name}}</text>
             </view>
           </view>
      </view>

    </scroll-view>
    
    
  </view>
  
  </view>
</template>

<script >
  import badgeMin from '@/mixins/tabbar-setBadge.js'
  export default {
    mixins:[badgeMin],
    data() {
      return {
        screenHeight:0 ,
        cateList:[],
        activeIndex:0,
        cateLevel2:[],
        scrollTop:0
      };
    },
    onLoad(){
      //获取窗口高度
      const windowInfo=uni.getWindowInfo()
      this.screenHeight=windowInfo.windowHeight-50
      
      //获取分类列表
      this.getCateList()
    },
      
    methods:{
      async getCateList(){
        const {data:res} =await uni.$http.get('/api/public/v1/categories')
        this.cateList=res.message
        this.cateLevel2=this.cateList[0].children
        
      },
      activeChange(index){
        this.activeIndex=index
        this.cateLevel2=this.cateList[index].children
        this.scrollTop=this.scrollTop?0:1
        
      },
      gotoGoodsList(item3){
        uni.navigateTo({
          url:'/subpck/goods_list/goods_list?cid='+item3.cat_id
        })
      },
      clickSearchHandler(param){
        uni.navigateTo({
          url:'/subpck/search/search'
        })
      }
      
    }
  
    
  }
</script>

<style lang="scss">
   .scroll-view-container {
     display: flex;
      .left-scroll-view {
        width: 120px;
        .left-scroll-item {
          line-height: 60px;
          background-color: #f7f7f7;
          text-align: center;
          font-size: 12px;
          //.left-scroll-view-item.active，同时匹配 .left-scroll-view-item 和 .active
          &.active {
            background-color: #ffffff;
            position: relative;
        
            &::before {
            content: '';
            display: block;
            width: 3px;
            height: 30px;
            background-color: #c00000;
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
          }
        }
      }
        
        
      }
      .right-scroll-view {
        
        .cate-level2-title {
          font-size: 12px;
          font-weight: bold;
          text-align: center;
          padding: 15px 0;
        }
        .cate-level3-list {
          display: flex;
          flex-wrap: wrap;
          .cate-level3-list-item {
          
            width: 33.33%;
            margin-bottom: 10px;
            display: flex;
            flex-direction: column;
            // text-align: center;  //水平轴
            align-items: center;   //垂直轴的水平对齐
           
            image {
            width: 60px;
            height: 60px;
           }
           text {
             font-size: 12px;
           }
          
         }
     
       
        }
      }
      
   
   }
</style>
